import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import lombok.Data;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class ExcelDemo {
    @Test
    public void write() {
        String filename = "/home/yongtay/a.xlsx";
        List<Person> list = new ArrayList<>();
        for(int i=0; i<5; i++) {
            Person person = new Person();
            person.setAge(18);
            person.setName("Tom-" + i);
            list.add(person);
        }
        EasyExcel.write(filename, Person.class).sheet("信息").doWrite(list);
        System.out.println("完成");
    }

    @Test
    public void read() {
        String filename = "/home/yongtay/a.xlsx";
        EasyExcel.read(filename, Person.class, new PersonReadListener()).sheet().doRead();
    }
}


class PersonReadListener implements ReadListener<Person> {

    @Override
    public void invoke(Person person, AnalysisContext analysisContext) {
        System.out.println(person);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("read finished...");
    }
}